const express = require('express');
const path = require('path');
let { query } = require('./api/models/db')
const server = express();


server.get('/api/login', (req, res) => {
  res.send("ok...")
})

server.post('/from', async (req, res) => {
  let { T1, T2, T3, T4, T5, T6, T7, T8, T9, T10,
    T11, T12, T13, T14, T15, T16, T17, T18, T19, T20,
    T21, T22, T23, T24, T25, T26, T27, T28 } = req.body;
  let data = await query(`insert into form values ('${null}','${T1}','${T2}','${T3}','${T4}','${T5}','${T6}','${T7}','${T8}','${T9}','${T10}','${T11}','${T12}','${T13}','${T14}','${T15}','${T16}','${T17}','${T18}','${T19}','${T20}','${T21}','${T22}','${T23}','${T24}','${T25}','${T26}','${T27}','${T28}',)`)
  if (data.length == 0) {
    res.send({
      code: 400,
      state: false,
      msg: "获取数据失败"
    })
    return
  }
  res.send({
    code: 200,
    state: true,
    data
  })
})

server.get('/', (req, res) => {
  res.sendFile(path.resolve(__dirname, './www/index.html'));
})

server.get('/result', (req, res) => {
  res.sendFile(path.resolve(__dirname, './www/result.html'));
})

// server.get('/login', (req, res) => {
//   res.sendFile(path.resolve(__dirname, './www/about.html'));
// })


server.use('/static', express.static(path.resolve(__dirname, './www')));


server.get('/api/data', (req, res) => {
  res.json({ code: 0, message: 'ok' });
})


server.listen(8000, '192.168.30.17', (error) => {
  console.log(error || 'ok.....');
})